package com.ruoyi.project.countrybus.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.framework.security.LoginBody;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.countrybus.domain.SysDriver;
import com.ruoyi.project.countrybus.service.ISysDriverService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 司机信息Controller
 * 
 * @author yangwenbo
 * @date 2022-04-05
 */
//@Api("司机信息管理")
@RestController
@RequestMapping("/countrybus/driver")
public class SysDriverController extends BaseController
{
    @Autowired
    private ISysDriverService sysDriverService;

    /**
     * 查询司机信息列表
     */
    @PreAuthorize("@ss.hasPermi('countrybus:driver:query')")
//    @ApiOperation("获取司机列表")
    @GetMapping("/list")
    public TableDataInfo list(SysDriver sysDriver)
    {
        startPage();
        List<SysDriver> list = sysDriverService.selectSysDriverList(sysDriver);
        return getDataTable(list);
    }

    /**
     * 导出司机信息列表
     */
    @PreAuthorize("@ss.hasPermi('countrybus:driver:query')")
    @Log(title = "司机信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysDriver sysDriver)
    {
        List<SysDriver> list = sysDriverService.selectSysDriverList(sysDriver);
        ExcelUtil<SysDriver> util = new ExcelUtil<SysDriver>(SysDriver.class);
        util.exportExcel(response, list, "司机信息数据");
    }

    /**
     * 获取司机信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('countrybus:driver:query')")
//    @ApiOperation("获取司机详情信息")
//    @ApiImplicitParam(name = "driverId", value = "司机ID", required = true, dataType = "long", paramType = "path", dataTypeClass = Long.class)
    @GetMapping(value = "/{driverId}")
    public AjaxResult getInfo(@PathVariable("driverId") Long driverId)
    {
        return AjaxResult.success(sysDriverService.selectSysDriverByDriverId(driverId));
    }

    /**
     * 获取司机信息详细信息，通过账号
     */
//    @ApiOperation("通过账号获取司机详情信息")
//    @ApiImplicitParam(name = "driverName", value = "司机ID", required = true, dataType = "string", paramType = "path", dataTypeClass = String.class)
    @GetMapping(value = "/name/{driverName}")
    public AjaxResult getInfoByName(@PathVariable("driverName") String driverName)
    {
        return AjaxResult.success(sysDriverService.selectSysDriverByDriverName(driverName));
    }



    /**
     * 新增司机信息
     */
    @PreAuthorize("@ss.hasPermi('countrybus:driver:add')")
//    @ApiOperation("新增司机信息")
    @Log(title = "司机信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysDriver sysDriver)
    {
        return toAjax(sysDriverService.insertSysDriver(sysDriver));
    }

    /**
     * 修改司机信息
     */
    @PreAuthorize("@ss.hasPermi('countrybus:driver:edit')")
//    @ApiOperation("修改司机信息")
    @Log(title = "司机信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysDriver sysDriver)
    {
        return toAjax(sysDriverService.updateSysDriver(sysDriver));
    }

    /**
     * 删除司机信息
     */
    @PreAuthorize("@ss.hasPermi('countrybus:driver:remove')")
//    @ApiOperation("删除司机信息")
    @Log(title = "司机信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{driverIds}")
    public AjaxResult remove(@PathVariable Long[] driverIds)
    {
        return toAjax(sysDriverService.deleteSysDriverByDriverIds(driverIds));
    }

//    @ApiOperation("司机端登陆验证")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "driverName", value = "司机账号", required = true, dataType = "String", paramType = "path", dataTypeClass = String.class),
//            @ApiImplicitParam(name = "password", value = "密码", required = true, dataType = "String", paramType = "path", dataTypeClass = String.class)
//    })
//    @GetMapping("/driverlogin/{driverName}/{password}")
//    public AjaxResult driverlogin(@PathVariable("driverName") String driverName,@PathVariable("password") String password)
//    {
//
//        SysDriver sysDriver = sysDriverService.selectSysDriverByDriverName(driverName);
//        String pass = sysDriver.getPassword();
//
//        if (StringUtils.equals(pass,password))
//        {
//            return AjaxResult.success(sysDriver);
////            return AjaxResult.success("登陆成功");
//        }
//        else
//        {
//            return error("用户不存在");
//        }
//    }

//    @ApiOperation("司机端找回密码")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "phonenumber", value = "司机手机号", required = true, dataType = "String", paramType = "path", dataTypeClass = String.class),
//            @ApiImplicitParam(name = "password", value = "密码", required = true, dataType = "String", paramType = "path", dataTypeClass = String.class)
//    })
//    @GetMapping("/findpassword/{phonenumber}/{password}")
//    public AjaxResult driverchangepassword(@PathVariable("phonenumber") String phonenumber,@PathVariable("password") String password)
//    {
//
//        SysDriver sysDriver = sysDriverService.selectSysDriverByDriverPhonenumber(phonenumber);
//        sysDriver.setPassword(password);
//
//        return toAjax(sysDriverService.updateSysDriver(sysDriver));
//    }


}
